package com.syni.mdd.yhd.common.all.service.impl.activity;

import com.syni.mdd.yhd.common.all.constants.Constants;
import com.syni.mdd.yhd.common.all.dao.jpa.activity.BmsMealPrizeRecordDao;
import com.syni.mdd.yhd.common.all.entity.activity.BmsMealPrize;
import com.syni.mdd.yhd.common.all.entity.activity.BmsMealPrizeRecord;
import com.syni.mdd.yhd.common.all.service.activity.BmsMealPrizeRecordService;
import com.syni.mdd.yhd.common.all.service.impl.BaseService;
import com.syni.mdd.yhd.common.all.utils.SpecificationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @className
 * @description TOO
 * @Author hwq
 * @DATE 2019/9/23 10:34
 * @VERSION 1.0
 **/
@Service
public class BmsMealPrizeRecordServiceImpl extends BaseService<BmsMealPrizeRecord, Integer> implements BmsMealPrizeRecordService {
    @Autowired
    BmsMealPrizeRecordDao bmsMealPrizeRecordDao;

    @Override
    public BmsMealPrizeRecordDao getBaseDao() {
        return bmsMealPrizeRecordDao;
    }

    @Override
    public BmsMealPrizeRecord findRecordByPrize(Integer id) {
        Optional<BmsMealPrizeRecord> bmsMealPrizeRecord = bmsMealPrizeRecordDao.findById(id);
        if(bmsMealPrizeRecord.isPresent()) {
            return bmsMealPrizeRecord.get();
        }
        return null;
    }

    @Override
    public List<BmsMealPrizeRecord> findUserGetCoupon(Integer userId,Integer type) {
        Map<String,Object> conditionMap = new HashMap<>();
        conditionMap.put("userId",userId);
        conditionMap.put("type", type);
        return bmsMealPrizeRecordDao.findAll(new SpecificationUtils(conditionMap));
    }

    @Override
    public void addUserPrizeRecord(Integer userId, BmsMealPrize bmsMealPrize) {
        BmsMealPrizeRecord bmsMealPrizeRecord = new BmsMealPrizeRecord();
        bmsMealPrizeRecord.setUserId(userId);
        bmsMealPrizeRecord.setPrizeId(bmsMealPrize.getId());
        bmsMealPrizeRecord.setType(bmsMealPrize.getType());
        bmsMealPrizeRecord.setFullCouponId(bmsMealPrize.getFullCouponId());
        bmsMealPrizeRecord.setBusinessCouponId(bmsMealPrize.getBusinessCouponId());
        bmsMealPrizeRecord.setWinTime(new Date());
        bmsMealPrizeRecordDao.save(bmsMealPrizeRecord);
    }
}
